﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Timers;
using Gfw.Infrastructure.Stock.Enums;
using Gfw.Repositories.Stock;
using Gfw.Web.Models.Stock;

namespace Gfw.BLL.Basic.Stock
{
    public static class StockMarket
    {
        public static void GetTendency(out List<decimal> vols, out List<decimal> prices, out List<string> dates)
        {

            TendencyRepository rep = new TendencyRepository();
            var list = rep.GetTendency30((int) TendencyTypeEnum.D1);
            vols = (from l in list select l.TendencyCount).ToList<decimal>();
            prices = (from l in list select l.TendencyPrice).ToList<decimal>();
            dates = (from l in list select l.TendencyDate.Value.ToShortDateString()).ToList<string>();
        }

        public static BargainModel GetBargainModel()
        {
            BargainModel model = new BargainModel();
            model.CurrentPrice = StockManager.CurrentPrice;

            WaitBargainPoolRepository rep = new WaitBargainPoolRepository();
            var sells = rep.GetTopSell5();
            model.SellItems = new List<BargainItem>();
            foreach (var s in sells)
            {
                model.SellItems.Add(new BargainItem() {Count = s.AgencyCount, Price = s.AgencyPrice});
            }
            while (model.SellItems.Count < 5)
            {
                model.SellItems.Add(new BargainItem() {Count = 0, Price = 0});
            }

            var buys = rep.GetTopBuy5();
            model.BuyItems = new List<BargainItem>();
            foreach (var b in buys)
            {
                model.BuyItems.Add(new BargainItem() {Count = b.AgencyCount, Price = b.AgencyPrice});
            }
            while (model.BuyItems.Count < 5)
            {
                model.BuyItems.Add(new BargainItem() {Count = 0, Price = 0});
            }
            return model;
        }

    }
}
